<template>
  <!-- 卡券核销 -->
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :model="form" :inline="true" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="流水单号">
              <el-input v-model="form.order_sn" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="姓名/手机号">
              <el-input v-model="form.keyword" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上级手机号">
              <el-input v-model="form.server_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8" width="236">
            <el-form-item label="核销时间">
              <el-date-picker
                v-model="dates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
              <!-- <el-input v-model="form.hospital_name" clearable /> -->
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8"> -->
          <el-col :span="6" :offset="2">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <el-button type="primary" @click="handleExport">导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="编号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column label="姓名" prop="realname" align="center" />
        <el-table-column label="手机号" prop="user_phone" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.user_phone |phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column label="上级" prop="server_phone" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.server_phone |phonereg}}</span>
          </template>
        </el-table-column>
        <el-table-column label="卡券名称" prop="name" align="center" />
        <el-table-column label="卡券状态" prop="status_name" align="center" />
        <el-table-column label="核销医院" prop="hospital_name" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.hospital_name | hospitalFn}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="是否升单" prop="office" align="center" /> -->
        <el-table-column label="流水单编号" prop="order_sn" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.order_sn | orderFn}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="升单金额" prop="office" align="center" /> -->
        <el-table-column label="核销时间" prop="check_time" align="center" />
        <!-- <el-table-column label="操作" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button size="small" type="text" v-if="scope.row">核销</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getCardList, cardExport } from "@/api/goddessMange";
import commonFn from "@/utils/common";
export default {
  name: "goddessCancelCard",
  data() {
    return {
      dates: null,
      form: {
        order_sn: "",
        keyword: "",
        server_phone: "",
        check_time_start: "",
        check_time_end: "",
        page: 1,
        size: 10
      },
      payDates: [],
      tableData: [{}],
      page_sizes: [5, 10, 20, 30],
      page_totals: 0,
      tableLoading: true
    };
  },
  created() {
    this.getList(this.form);
  },
  filters: {
    // 核销医院
    hospitalFn(opt) {
      if (opt) {
        return opt;
      } else {
        return "--";
      }
    },
    orderFn(opt) {
      if (opt) {
        return opt;
      } else {
        return "--";
      }
    }
  },
  methods: {
    // 序号
    table_index(index) {
      return (this.form.page - 1) * this.form.size + index + 1;
    },
    // 卡券列表
    getList(opt) {
      getCardList(opt)
        .then(res => {
          if (res.data.code == 200) {
            this.tableData = res.data.data;
            this.page_totals = res.data.meta.total;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading = false;
        })
        .catch(err => {
          this.errorStatus(err.msg);
          this.tableLoading = false;
        });
    },
    // 查询
    handleSearch() {
      this.form.page = 1;
      if (this.dates != null) {
        if (this.dates.length > 0) {
          this.form.check_time_start = this.dates[0];
          this.form.check_time_end = this.dates[1];
        } else {
          this.form.check_time_start = null;
          this.form.check_time_end = null;
        }
      } else {
        this.form.check_time_start = null;
        this.form.check_time_end = null;
      }
      this.getList(this.form);
    },
    // 导出
    handleExport() {
      let data = { ...this.form };
      delete data.page;
      delete data.size;
      cardExport(data)
        .then(res => {
          commonFn.downFile("女王卡卡券核销列表导出", res);
        })
        .catch(err => {
          this.errorStatus(err.msg);
        });
    },
    // 改变页面显示条数
    handleSizeChange(val) {
      this.form.size = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, "error");
    }
  }
};
</script>
<style scoped>
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.pagesCon {
  margin-top: 20px;
  text-align: right;
}
</style>
